package com.ruoyi.project.WebMoudle.userPick.controller;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.WebMoudle.shopPick.domain.PickSum;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.userPick.domain.UserPick;
import com.ruoyi.project.WebMoudle.userPick.service.IUserPickService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户提现Controller
 * 
 * @author ruoyi
 * @date 2020-07-20
 */
@Controller
@RequestMapping("/userPick/userPick")
public class UserPickController extends BaseController
{
    private String prefix = "userPick/userPick";

    @Autowired
    private IUserPickService userPickService;

    @RequiresPermissions("userPick:userPick:view")
    @GetMapping()
    public String userPick()
    {
        return prefix + "/userPick";
    }

    /**
     * 查询用户提现列表
     */
    @RequiresPermissions("userPick:userPick:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserPick userPick)
    {
        startPage();
        List<UserPick> list = userPickService.selectUserPickList(userPick);
        PickSum pickSum = userPickService.queryMoneySum(userPick);
        if (!StringUtils.isNotNull(pickSum)){
            pickSum = new PickSum();
        }
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        rspData.setPickSum(pickSum);
        return rspData;
    }

    /**
     * 导出用户提现列表
     */
    @RequiresPermissions("userPick:userPick:export")
    @Log(title = "用户提现", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserPick userPick)
    {
        List<UserPick> list = userPickService.selectUserPickList(userPick);
        ExcelUtil<UserPick> util = new ExcelUtil<UserPick>(UserPick.class);
        return util.exportExcel(list, "userPick");
    }

    /**
     * 新增用户提现
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户提现
     */
    @RequiresPermissions("userPick:userPick:add")
    @Log(title = "用户提现", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserPick userPick)
    {
        return toAjax(userPickService.insertUserPick(userPick));
    }

    /**
     * 修改用户提现
     */
    @GetMapping("/edit/{orderNum}")
    public String edit(@PathVariable("orderNum") String orderNum, ModelMap mmap)
    {
        UserPick userPick = userPickService.selectUserPickById(orderNum);
        mmap.put("userPick", userPick);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户提现
     */
    @RequiresPermissions("userPick:userPick:edit")
    @Log(title = "用户提现", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserPick userPick)
    {
        return toAjax(userPickService.updateUserPick(userPick));
    }

    /**
     * 删除用户提现
     */
    @RequiresPermissions("userPick:userPick:remove")
    @Log(title = "用户提现", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userPickService.deleteUserPickByIds(ids));
    }
}
